通过任务计划程序和Powershell脚本实现自动安装Windows补丁

您所在的位置:网站首页 安装补丁程序的方法通常有 手工操作 通过任务计划程序和Powershell脚本实现自动安装Windows补丁

通过任务计划程序和Powershell脚本实现自动安装Windows补丁

#通过任务计划程序和Powershell脚本实现自动安装Windows补丁| 来源: 网络整理| 查看: 265

域控补丁通过任务计划程序安装,输出日志方便确认安装情况

多域控安装 同时输出日志到同一目录

后期进一步修改以实现自动设立和删除任务计划程序,避免多余操作

注意:

1.任务计划程序中需要在启动程序填 powershell 在参数栏填写脚本路径 否则将以默认notepad打开脚本

2.无法运行时需要修改脚本执行权限

参考关于powershell脚本运行权限的信息:关于执行策略 - PowerShell | Microsoft Docs

第一个计划任务设置定时启动  

#启用WindowsUpdate服务 Set-Service wuauserv -StartupType Manual Start-Service wuauserv #申明变量 $hostname = hostname $time = Get-Date $log = '' $patch = ''" echo "$hostname $time EnableWindowsUpdate " |Out-File -Append $log #输出当前服务状态 Get-Service -Name wuauserv |Out-File -Append $log echo "$hostname Installing... " |Out-File -Append $log #遍历目录内文件,如有其他文件添加筛选(*.msu),添加/quiet确保无人值守运行 /norestart确保安装完目录内全部补丁 #cmd命令可使用 FOR /R %%F IN (*.msu) DO start /wait wusa %%F /quiet /norestart forfiles /p $patch /c "cmd /c wusa @path /quiet /norestart" #服务器可能存在多账户登录后台驻留的情况 需要添加Force参数保证可以重启 Restart-Computer -Force

第二个计划程序设立为系统启动时运行,可根据需要添加延迟时间  

$hostname = hostname $time = Get-Date $log = '' #禁用WindowsUpdate服务 Stop-Service wuauserv Set-Service wuauserv -StartupType Disabled echo "$hostname $time DisableWindowsUpdate " |Out-File -Append $log #输出服务状态 Get-Service -Name wuauserv |Out-File -Append $log #输出域控状态 repadmin /replsummary | Out-File -Append $log repadmin /syncall | Out-File -Append $log #输出补丁安装列表 wmic qfe list | Out-File -Append $log exit

"本站所有文章均为原创,欢迎转载,请注明文章出处:https://blog.csdn.net/weixin_57323573?type=blog。本人习惯不定期对自己的博文进行修正和更新,因此请访问出处以查看本文的最新版本。"



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3